import 'dart:io';
import 'package:flutter/material.dart';
import '../utils/word_import_export_util.dart';

class TestCsvImport extends StatelessWidget {
  const TestCsvImport({Key? key}) : super(key: key);

  Future<void> _testImport(BuildContext context) async {
    try {
      // 测试导入功能
      final result = await WordImportExportUtil.importWordsFromCSVOrExcel();
      
      // 显示导入结果
      if (result.hasErrors) {
        ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(content: Text('导入出现错误: ${result.errors.join("\n")}'))
        );
      } else {
        ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(content: Text('成功导入 ${result.words.length} 个单词'))
        );
      }
    } catch (e) {
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(content: Text('导入失败: $e'))
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('测试CSV导入')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
              onPressed: () => _testImport(context),
              child: const Text('测试导入CSV/Excel'),
            ),
          ],
        ),
      ),
    );
  }
}